﻿<%@ Page Language="C#" %>
<%@ Import Namespace="ExaminationSys.Helper" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Login Examination System</title>   
    <link href="../Styles/Examination.css" rel="stylesheet" type="text/css" /> 
    <style type="text/css">
        h1 {
            font: normal 60px tahoma, arial, verdana;
            color: #E1E1E1;
        }
        
        h2 {
            font: normal 20px tahoma, arial, verdana;
            color: #E1E1E1;
        }
        
        h2 a {
            text-decoration: none;
            color: #E1E1E1;
        }
        
        .x-window-mc {
            background-color : #F4F4F4 !important;
        }
        
        #Window1-body
        {
            padding:5px;
        }
    </style>
    <script type="text/javascript">
        if (window.top.frames.length !== 0) {
            window.top.location = self.document.location;
        }
    </script>
    <script runat="server">
    
    protected void Login_Click(object sender, DirectEventArgs e)
    {
        var formsAuth = new FormsAuthenticationHelper.FormsAuthenticationService();
        var textUserName = this.txtUsername.Text;
        var password = txtPassword.Text;

        var retCode = FormsAuthenticationHelper.Login(textUserName, password);

        if (retCode == -1)
        {
            MessageBoxHelper.ShowWarning("用户名或者密码不正确");
            return;
        }
        else if (retCode == -2)
        {
            MessageBoxHelper.ShowWarning("没有访问权限");
            return;
        }
        formsAuth.SignIn(textUserName, false);
        Response.Redirect("~/Default.aspx");
    }
</script>
</head>
<body>
    <form id="Form1" runat="server">
      <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <h1>Examination System</h1>
    <h2>Powered by Ext.Net</h2>
     <ext:Window 
            ID="Window1" 
            runat="server" 
            Closable="false"
            Resizable="false"
            Height="150" 
            Icon="Lock" 
            Title="登录"
            Draggable="false"
            Width="350"
            Modal="true"
            Padding="10"
            Layout="Form">
            <Items>
                <ext:TextField 
                    ID="txtUsername" 
                    runat="server" 
                    FieldLabel="管理员帐户" 
                    AllowBlank="false"
                    BlankText="Your username is required."
                    Text=""
                    AnchorHorizontal="100%"
                    />
                <ext:TextField 
                    ID="txtPassword" 
                    runat="server" 
                    InputType="Password" 
                    FieldLabel="密码" 
                    AllowBlank="false" 
                    BlankText="Your password is required."
                    Text=""
                    AnchorHorizontal="100%"
                    />
            </Items>
            <Buttons>
                <ext:Button ID="btnLogin" runat="server" Text="Login" Icon="Accept">
                    <Listeners>
                        <Click Handler="
                            if (!#{txtUsername}.validate() || !#{txtPassword}.validate()) {
                                Ext.Msg.show({title:'提示信息',msg:'用户名和密码不能为空',buttons:Ext.Msg.OK,icon:Ext.MessageBox.WARNING});
                                // return false to prevent the Login_Click Ajax Click event from firing.
                                return false; 
                            }" />
                    </Listeners>
                    <DirectEvents>
                        <Click OnEvent="Login_Click">
                            <EventMask ShowMask="true" Msg="Loading..." MinDelay="500" />
                        </Click>
                    </DirectEvents>
                </ext:Button>
            </Buttons>
        </ext:Window>
    </form>
</body>
</html>
